--- @param extension Package
--- @param HY HY_Utility
--- @param U Utility
return function(extension, HY, U)
    local hy_nippaku_zanmu = General:new(extension, "hy_nippaku_zanmu", "chi_k", 3, 3, General.Female)
    local disengage_shadow = fk.CreateSkill {
        name = "disengage_shadow",
    }
    disengage_shadow:addEffect(fk.GameStart, {
        anim_type = "negative",
        can_trigger = function(self, event, target, player, data)
            if not player:hasSkill(disengage_shadow.name) then
                return false
            end
            return true
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            room:addPlayerMark(player, "@disengage_shadow", 1)
        end
    })
    disengage_shadow:addEffect(fk.Damaged, {
        anim_type = "negative",
        can_trigger = function(self, event, target, player, data)
            if not player:hasSkill(disengage_shadow.name) then
                return false
            end
            return target == player and player:getMark("@disengage_shadow") < 3
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            room:addPlayerMark(player, "@disengage_shadow", 1)
        end
    })
    local submit_to_king = fk.CreateSkill {
        name = "submit_to_king",
    }
    submit_to_king:addEffect(fk.TurnEnd, {
        anim_type = "defensive",
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(submit_to_king.name) and target ~= player and player:getMark("@disengage_shadow") > player:getMark("submit_to_king-turn") and not target.dead
        end,
        on_cost = function(self, event, target, player, data)
            local room = player.room
            local choices = { "submit_to_king_draw", "submit_to_king_view", "Cancel" }
            if target:isKongcheng() then
                table.removeOne(choices, "submit_to_king_view")
            end
            event:setCostData(self, room:askToChoice(player, {
                choices = choices,
                skill_name = submit_to_king.name,
                prompt = "submit_to_king_choice_prompt::" .. target.id
            }))
            return event:getCostData(self) ~= "Cancel"
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            if event:getCostData(self) == "submit_to_king_draw" then
                if not player.dead then
                    room:drawCards(player, 1, submit_to_king.name)
                end
            elseif event:getCostData(self) == "submit_to_king_view" then
                local count = math.clamp(player:getMark("@disengage_shadow"), 1, #target:getCardIds("h"))
                local cards = room:askToChooseCards(player, {
                    target = target,
                    min = 1,
                    max = count,
                    flag = "h",
                    skill_name = submit_to_king.name
                })
                room:setPlayerMark(player, "submit_to_king", cards)
                room:setPlayerMark(player, "submit_to_king_target", target.id)
                HY.AddCardsToTemp(player, cards)
                local _, use = room:askToUseActiveSkill(player, {
                    skill_name = "submit_to_king_active",
                    prompt = "submit_to_king_prompt::" .. target.id
                })
                HY.RemoveTempCards(player)
                room:setPlayerMark(player, "submit_to_king", 0)
                room:setPlayerMark(player, "submit_to_king_target", 0)
                if use then
                    local card = Fk:getCardById(use.cards[1])
                    room:setCardMark(card, "submit_to_king", 1)
                    room:useCard({
                        from = target,
                        card = card,
                        tos = use.targets,
                        extraUse = true,
                        disresponsiveList = room:getAlivePlayers(),
                    })
                end
            end
        end,
    })
    submit_to_king:addEffect(fk.Damaged, {
        can_refresh = function(self, event, target, player, data)
            return player:hasSkill(submit_to_king.name, true, true) and data.from and data.from == player.room.current
        end,
        on_refresh = function(self, event, target, player, data)
            player.room:addPlayerMark(player, "submit_to_king-turn", data.damage)
        end
    })
    local submit_to_king_active = fk.CreateSkill {
        name = "submit_to_king_active",
    }
    submit_to_king_active:addEffect("active", {
        card_num = 1,
        card_filter = function(self, player, to_select, selected)
            return #selected == 0 and table.contains(player:getTableMark("#tempMove"), to_select)
        end,
        expand_pile = function(self, player)
            return player:getTableMark("#tempMove")
        end,
        feasible = function(self, player, selected, selected_cards, card)
            if #selected_cards == 0 then
                return false
            end
            local card = Fk:getCardById(selected_cards[1])
            if card.name == "collateral" then
                return #selected == 2
            else
                return #selected == 1
            end
        end,
        target_filter = function(self, player, to_select, selected, selected_cards)
            local room = Fk:currentRoom()
            if #selected_cards == 0 then
                return false
            end
            if to_select.id == player:getMark("submit_to_king_target") then
                return false
            end
            local from = room:getPlayerById(player:getMark("submit_to_king_target"))
            local to = to_select
            local card = Fk:getCardById(selected_cards[1])
            if card.name == "collateral" then
                if #selected >= 2 then
                    return false
                end
                if #selected == 0 then
                    return from:canUseTo(card, to, { bypass_distances = true, bypass_times = true })
                else
                    return selected[1]:inMyAttackRange(to) and from:canUseTo(card, selected[1])
                end
            else
                return #selected == 0 and from:canUseTo(card, to, { bypass_distances = true, bypass_times = true })
            end
        end,
    })
    local king_arise = fk.CreateSkill {
        name = "king_arise",
        tags = {
            Skill.Limited,
        }
    }
    king_arise:addEffect(fk.EventPhaseStart, {
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(king_arise.name) and player:hasSkill("disengage_shadow", true) and target == player and player.phase == Player.Start and
                player:usedSkillTimes(king_arise.name, Player.HistoryGame) < 1 and player:getMark("@disengage_shadow") >= 3
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            room:handleAddLoseSkills(player, "-disengage_shadow")
            room:removePlayerMark(player, "@disengage_shadow", 3)
            room:changeMaxHp(player, 1)
            room:throwCard(player:getCardIds("j"), king_arise.name, player, player)
            room:setPlayerMark(player, "king_arise", 1)
        end,
    })
    king_arise:addEffect("targetmod", {
        bypass_times = function(self, player, skill, scope, card, to)
            return player:getMark("king_arise") ~= 0
        end,
        bypass_distances = function(self, player, skill, card, to)
            return player:getMark("king_arise") ~= 0
        end,
    })
    extension:loadSkillSkels { disengage_shadow, submit_to_king, submit_to_king_active, king_arise }
    hy_nippaku_zanmu:addSkill("disengage_shadow")
    hy_nippaku_zanmu:addSkill("submit_to_king")
    hy_nippaku_zanmu:addSkill("king_arise")
    Fk:loadTranslationTable {
        ["hy_nippaku_zanmu"] = "日白残无",
        ["#hy_nippaku_zanmu"] = "反影为主",
        ["illustrator:hy_nippaku_zanmu"] = "久蒼穹",
        ["designer:hy_nippaku_zanmu"] = "黑曜人形",
        ["cv:hy_nippaku_zanmu"] = "",

        ["disengage_shadow"] = "寂影",
        [":disengage_shadow"] = "游戏开始时，你获得1枚“影”标记。在你受到伤害后，你获得1枚“影”标记（至多为3）。",
        ["@disengage_shadow"] = "影",

        ["submit_to_king"] = "掌伏",
        [":submit_to_king"] = "其他角色的回合结束时，若其本回合造成伤害值小于X，你可以选择一项：1.摸一张牌；2.观看其一至X张手牌，然后你可以令其对你指定的另一名角色使用其中一张牌（无距离限制且不可被响应）（X为你的“影”的数量）。",
        ["submit_to_king_prompt"] = "掌伏：你可以使用其中一张牌（视为由%dest使用）",
        ["submit_to_king_choice_prompt"] = "掌伏：选择对%dest执行的一项",

        ["submit_to_king_active"] = "掌伏",
        ["submit_to_king_draw"] = "摸一张牌",
        ["submit_to_king_view"] = "观看其手牌",

        ["king_arise"] = "王现",
        [":king_arise"] = "限定技，准备阶段，你可以移除3枚“影”并失去“寂影”，然后增加1点体力上限并弃置判定区所有牌。若如此做，本局游戏你使用牌无次数与距离限制。",
        ["#king_arise_targetmod"] = "王现",
    }
end
